package net.searchdata.study;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class Entry23Two {
	private int numElementsInCommon(Set<?> set1, Set<?> set2) {
		int result = 0;
		for (Object o : set1) {
			if (set2.contains(o)) {
				result++;
			}
		}

		return result;
	}
	
	@Test
	public void test3() {
		Set<Integer> intSet1 = new HashSet<Integer>();
		Set<Integer> intSet2 = new HashSet<Integer>();

		intSet1.add(1);
		intSet1.add(2);
		intSet1.add(3);

		intSet2.add(2);
		intSet2.add(3);
		intSet2.add(4);

		assertThat(numElementsInCommon(intSet1, intSet2), is(2));
	}
}
